function Graph(data){
	var _this=this;
	this.memDeep = 1;
	this.curves = [];
	this.place = $("#placeholder");
	this.channels = [];
	this.data = data;
	data.setGraph(this);
	this.addCurve = function(curve){
		this.curves.push(curve);
	}
	this.getCurve = function(id){
		for (var i=0; i< this.curves.length; i++) if (this.curves[i].id == id) return this.curves[i];
		return null;
	}
	this.paintAll = function(){
		var arr2Paint = [];
		var arrAvg = [];
		var empty = true;
		for(var k in this.channels){
			var ch = this.channels[k];
		//	console.log('plots -'+ch.name, ch.plots);
		//	console.log('hist - '+ch.name, ch.history);
			if (ch.active){
				for (var i = ch.deep-1; i>=0; i--){
					var w = ch.deep-ch.howOld(i);
					//console.log(ch.transparency(i));
					//console.log("OLD:", ch.howOld(i));
					//console.log(ch);
					arr2Paint.push({	lines:{lineWidth:ch.lw(i)},
										color:color.rgba(ch.colors[0], ch.transparency(i)), 
										data:ch.history[i]});
					$.plot('#placeholder', arr2Paint);
				}
				arr2Paint.push({lines:{lineWidth:ch.deep+2},color:ch.colors[0], data: ch.plots});
				$.plot("#placeholder", arr2Paint);
				empty = false;
			}
			
			for(var i = 0; i<controls.par.length; i++){
				if (ch.disp[controls.par[i]]){
//					var dashes=i==0?true:false;
					var dashes=true;
					arr2Paint.push({lines:{lineWidth:1}, 
									color:color.rgba(ch.colors[0],0.7), 
									data:ch[controls.par[i].toLowerCase()],
									dashes:{show:dashes}});
					$.plot("#placeholder", arr2Paint);
				}
			}
		}
		
		if (empty) $.plot("#placeholder",[[0,0]]);		
		
	}
	this.addChannel = function (metapack){
		var channel = new Channel(this, metapack);
		controls.addLeftBut(channel);
		this.channels[channel.name]=channel;
	};
	this.addRow = function(regpack){ 
		this.curRow = new Row(this, regpack); 
		
	};
	this.clear = function(){
		this.channels=[];
		this.curRow = null;
	}
	this.reset = function(){
		this.data = new Data();
	}
	this.setMemoryDeep = function(deep){
		//alert(deep);
		this.memDeep = deep;
		for (var key in this.channels){
			if (this.channels[key].deep < deep) this.data.blank = true;
			this.channels[key].deep = deep;
		}
		this.data.reload();
		this.paintAll();
	}
}
